package cn.stylefeng.guns.sys.modular.system.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.BtyPerformanceMonthInformation;
import cn.stylefeng.guns.sys.modular.system.model.params.AttendAuditBtyAreaParam;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyPerformanceMonthInformationPageListParam;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyPerformanceMonthInformationParam;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyPerformanceReceiveParam;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyPerformanceSelectResult;
import cn.stylefeng.guns.sys.modular.system.service.BtyPerformanceMonthInformationService;
import cn.stylefeng.guns.sys.modular.system.service.BtyPerformancePointService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;


/**
 * 控制器
 *
 * @author wjk
 * @Date 2022-02-10 14:38:19
 */
@Controller
@RequestMapping("/btyPerformanceMonthInformation")
public class BtyPerformanceMonthInformationController extends BaseController {

    private String PREFIX = "/modular/system/btyPerformanceMonthInformation";

    @Autowired
    private BtyPerformanceMonthInformationService btyPerformanceMonthInformationService;

    @Autowired
    private BtyPerformancePointService btyPerformancePointService;

    /**
     * 跳转到主页面
     *
     * @author wjk
     * @Date 2022-02-10
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/btyPerformanceMonthInformation.html";
    }

    /**
     * 新增页面
     *
     * @author wjk
     * @Date 2022-02-10
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/btyPerformanceMonthInformation_add.html";
    }

    /**
     * 编辑页面
     *
     * @author wjk
     * @Date 2022-02-10
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/btyPerformanceMonthInformation_edit.html";
    }

    /**
     * 新增接口
     *
     * @author wjk
     * @Date 2022-02-10
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(BtyPerformanceMonthInformationParam btyPerformanceMonthInformationParam) {
        this.btyPerformanceMonthInformationService.add(btyPerformanceMonthInformationParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author wjk
     * @Date 2022-02-10
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(BtyPerformanceMonthInformationParam btyPerformanceMonthInformationParam) {
        this.btyPerformanceMonthInformationService.update(btyPerformanceMonthInformationParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author wjk
     * @Date 2022-02-10
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(BtyPerformanceMonthInformationParam btyPerformanceMonthInformationParam) {
        this.btyPerformanceMonthInformationService.delete(btyPerformanceMonthInformationParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author wjk
     * @Date 2022-02-10
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(BtyPerformanceMonthInformationParam btyPerformanceMonthInformationParam) {
        BtyPerformanceMonthInformation detail = this.btyPerformanceMonthInformationService.getById(btyPerformanceMonthInformationParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author wjk
     * @Date 2022-02-10
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(BtyPerformanceMonthInformationParam btyPerformanceMonthInformationParam) {
        return this.btyPerformanceMonthInformationService.findPageBySpec(btyPerformanceMonthInformationParam);
    }

    /**
     * 1.查询姓名列表
     *
     * @author ws
     * @Date 2022-02-10
     */
    @ResponseBody
    @RequestMapping("/listXm")
    public LayuiPageInfo listXm(BtyPerformanceMonthInformationParam btyPerformanceMonthInformationParam) {
        return this.btyPerformanceMonthInformationService.findPageXm(btyPerformanceMonthInformationParam);
    }

    /**
     * ws
     * 2.查询上个月
     */
    @ResponseBody
    @PostMapping("/getLastDay")
    public ResponseData  getPerformanceDay(){
        Map<String,String> map = this.btyPerformancePointService.getAttendMonth();
        return ResponseData.success(map);
    }

    /**
     * ws
     * 3.查询所有营运经理
     */
    @ResponseBody
    @PostMapping("/listYyjl")
    public LayuiPageInfo listYyjl(BtyPerformanceMonthInformationParam btyPerformanceMonthInformationParam){
        return this.btyPerformanceMonthInformationService.findPageYyjl(btyPerformanceMonthInformationParam);
    }

    /**
     * ws
     * 4.查询所有督导(可以根据营运经理电话)
     */
    @ResponseBody
    @PostMapping("/listDd")
    public LayuiPageInfo listDd(AttendAuditBtyAreaParam param){
        return this.btyPerformanceMonthInformationService.findPageDd(param);
    }

    /**
     * ws
     * 5.查询所有门店(可以根据营运经理电话，督导电话)
     */
    @ResponseBody
    @PostMapping("/listDm")
    public LayuiPageInfo listDm(AttendAuditBtyAreaParam param){
        return this.btyPerformanceMonthInformationService.findPageDm(param);
    }

    /**
     * ws
     * 6.查询绩效明细
     */
    @ResponseBody
    @PostMapping("/listPage")
    public ResponseData listPage(BtyPerformanceMonthInformationPageListParam param){
        if(ObjectUtil.isEmpty(param.getMonth())){
            return ResponseData.error(200,"缺少日期",false);
        }
        return ResponseData.success(this.btyPerformanceMonthInformationService.findPage(param));
    }
    /**
     * ws
     * 7.一键驳回，驳回店上个月的数据
     */
    @ResponseBody
    @PostMapping("/rejectMd")
    public ResponseData rejectMd(BtyPerformanceMonthInformationPageListParam param){
        return ResponseData.success(this.btyPerformanceMonthInformationService.rejectMd(param));
    }

    /**
     * 8.统计店的个数信息
     * @author ws
     * @Date 2021-02-14
     */
    @ResponseBody
    @PostMapping("/getShopCount")
    public ResponseData  getShopListSumByPhone(BtyPerformanceMonthInformationPageListParam param){

        //统计门店数
        Map<String,String> map = this.btyPerformanceMonthInformationService.getShopCount(param);
        return ResponseData.success(map);
    }

    /**
     * 9.导出excel表格
     * @author ws
     * @Date 2021-02-14
     */
    @ResponseBody
    @RequestMapping("/exportList")
    public ResponseEntity<byte[]> accountLedgerExport(HttpServletRequest request, HttpServletResponse response, BtyPerformanceMonthInformationPageListParam param) {
        return this.btyPerformanceMonthInformationService.exportList(request, response, param);
    }
}


